package com.zhaoc.service.impl;

import com.zhaoc.dao.StandardRepository;
import com.zhaoc.domain.Standard;
import com.zhaoc.service.IStandardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class StandardServiceImpl implements IStandardService {

	@Autowired

	private StandardRepository standardRepository;

	//保存新的收派标准
	@Override
	@CacheEvict(value = "standard")//清空缓冲名字为standard的缓存区
	public void save(Standard standard) {
		System.out.println(standard);
		standardRepository.save(standard);
	}

	//查询所有收派标准
	@Override
	@Cacheable("standard")//把查到的数据添加到standard的缓存区
	public List<Standard> findAll() {
		return standardRepository.findAll();
	}

	//分页查询数据
	@Override
	@Cacheable(value = "standard",key = "#pageable.pageNumber+'_'+#pageable.pageSize")
	public Page<Standard> findPageData(Pageable pageable) {
		return standardRepository.findAll(pageable);
	}

}
